package com.thread.learn.thread7;

/**
 * 保证可见性的前提
 * 多个线程拿到的是同一把锁
 * 
 * @author feelj
 *
 */
public class Demo {
	
	public volatile int a=1;

	public static void main(String[] args) {
		
		Demo demo=new Demo();
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				demo.a=10;		
			}
		}).start();
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println(demo.a);		
			}
		}).start();
		
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		System.out.println(demo.a);
		
	}
	

}
